% \documentclass{memoir}
% \pagestyle{empty} % 移除页眉页脚
% \setlrmarginsandblock{0pt}{0pt}{*} % 左右边距设为 0
% \setulmarginsandblock{0pt}{0pt}{*} % 上下边距设为 0
% \checkandfixthelayout % 应用布局设置
\documentclass{article}
% \documentclass{standalone}
\usepackage{algorithmicx}
\usepackage{geometry}
\geometry{
    % a4paper,.
    top=1cm,
    % top=2.2cm, bottom=2.2cm, 
    bottom=1cm,
    left=0cm, right=0cm,
}

\pagestyle{empty} %取消页码数

\usepackage[linesnumbered,ruled,vlined,algo2e]{algorithm2e}
% \usepackage[linesnumbered,ruled,vlined,algo2e,breakable]{algorithm2e}
% \SetAlgoLined：增添end行
% \DontPrintSemicolon：不显示行末尾的分号
% \SetKwInput{KwInput}{Input}：设置输入
% \SetKwInOut{KwInput}{Input}：设置输入输出
% ruled：标题左对齐，顶部和底部各添加一条线
% linesnumbered：显示行编号
\usepackage{ctex} %注意，这里必须引入ctex,否则中文内容无法输出
\SetKwRepeat{Do}{do}{while}
\SetKwFunction{Try}{try}
\SetKwFunction{Catch}{catch}
% \SetKwProg{TryCatch}{Try}{Catch}{}

\begin{document}
% \begin{adjustbox}{max totalsize={\textwidth}{\textheight}}
\begin{algorithm2e}[htbp]
    \SetAlgoLined
    \renewcommand{\thealgocf}{4-2} %自定义算法编号
    \caption{AST抽象语法树-函数信息提取}
    \SetKwInOut{KwIn}{\textbf{输入}}
    \SetKwInOut{KwOut}{\textbf{输出}}	

    % \KwIn{抽象语法树入口节点:$node$}
    % \KwOut{函数信息列表:$functions$}

    \KwIn{abstract syntax tree entry node:$node$}
    \KwOut{list of function information:$functions$}

    \SetKwFunction{FMain}{visit\_FunctionDef}
    \SetKwProg{Fn}{Function}{}{}
        \Fn{\FMain{self,node}}{
            closures,complexity $\gets$ analyze\_function\_body(node.body) \\
            function\_info $\gets$ create\_funtion\_info(node,closures,complexity) \\
            self.functions.append(function\_info) //添加函数信息
    }\textbf{end}


    \SetKwFunction{FMain}{analyze\_function\_body}
    \SetKwProg{Fn}{Function}{}{}
        \Fn{\FMain{node\_bodys}}{
            closures:List $\gets$ Empty \\
            complexity=1 //初始化复杂度为1 \\
            \For{child\_node in node\_bodys}{
                visitor=ComplexityVisitor() \\
                visitor.visit(child\_node) \\
                Append(closures,visitor.functions)\\
                complexity += visitor.complexity //计算闭包函数复杂度，累加 \\
                \Return{ closures, complexity}
            }
    }\textbf{end}

    \SetKwFunction{FMain}{ create\_function\_info}
    \SetKwProg{Fn}{Function}{}{}
        \Fn{\FMain{node,closures,complexity}}{
            endline $\gets$ Max(node.lineno,Call(getattr(visitor, 'max\_line'))) //更新当前函数块最大行数 \\

            \Return{
                Func $\gets$
                \begin{tabular}{ll}
                    name        & $= node.name$ \\
                    start\_line     & $= node.lineno$ \\
                    % col\_offset & $= node.col\_offset$ \\
                    end\_line   & $= end\_line$ \\
                    % is\_method  & $= self.to\_method$ \\
                    % class\_name & $= self.classname$ \\
                    closures    & $= closures[0]$ \\
                    complexity  & $= complexity$ \\
                \end{tabular}
            }
    }\textbf{end}

% \end{adjustbox}
\end{algorithm2e}
\end{document}    